package com.ljchen.formalProject.frame.vo;

import com.ljchen.formalProject.enums.ResultCode;
import lombok.Data;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
public class Result<T> implements Serializable {

    private static final long serializableUID = 1L;

    private int statusCode;

    private String message;

    private String appStartTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());

    private String requestId;

    private T data;

    public Result() {
    }

    public Result(ResultCode resultCode, T data) {
        this.statusCode = resultCode.getCode();
        this.message = resultCode.getMessage();
//        this.requestId = requestId;
        this.data = data;
    }

    public static <T> Result<T> ok() {
        Result<T> result = new Result<>(ResultCode.SUCCESS, null);
        return result;
    }

    public static <T> Result<T> ok(T data) {
        Result<T> result = new Result<>(ResultCode.SUCCESS, data);
        return result;
    }

    public static <T> Result<T> error() {
        Result<T> result = new Result<>(ResultCode.ERROR, null);
        return result;
    }

    public static <T> Result<T> error(T data) {
        Result<T> result = new Result<>(ResultCode.ERROR, data);
        return result;
    }

    public static <T> Result<T> error(ResultCode resultCode, T data) {
        Result<T> result = new Result<>(resultCode, data);
        return result;
    }

}
